package com.dmcb.trade.business.crawlers.article;

import com.dmcb.trade.business.constants.CrawlConstant;
import com.dmcb.trade.business.entities.Article;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.springframework.stereotype.Service;

/**
 * Created by 黑米 on 2017/3/8.
 */
@Service
public class QuanJiHangMuParser  extends BaseParser {

    /**
     * 网站URL网址
     *
     * @return 链接
     */
    @Override
    protected String url() {
        return CrawlConstant.QUANJIHANGMU_URL;
    }

    /**
     * 获取标题选择器
     *
     * @return 标题选择器
     */
    @Override
    protected String titleSelect() {
        return "h1.tt_h";
    }

    /**
     * 获取日期选择器
     *
     * @return 发布日期选择器
     */
    @Override
    protected String dateSelect() {
        return "p.txt_c";
    }

    /**
     * 获取正文内容选择器
     *
     * @return 正文内容选择器
     */
    @Override
    protected String bodySelect() {
        return "div.fz14";
    }

    /**
     * 获取封面选择器
     *
     * @return 封面选择器
     */
    @Override
    protected String coverSelect() {
        return "div.fz14>p img[src]";
    }

    /**
     * 获取作者选择器
     *
     * @return 作者选择器
     */
    @Override
    protected String authorNameSelect() {
        return "p.txt_c";
    }

    @Override
    protected void setAuthorName(Document doc, Article article) {
        Element authorElement = doc.select(authorNameSelect()).first();
        if(authorElement == null){
            return;
        }
        //时间:2017-03-07 16:54 来源:本站原创 作者:machine 点击:
        String author = authorElement.text();
        author = author.substring(author.indexOf("作者")+3,author.indexOf("点击")).trim();
        article.setAuthorName(author);
    }

    @Override
    protected boolean isProxyEnabled() {
        return true;
    }

    @Override
    protected String platform() {
        return "拳击航母";
    }
}
